<template>
  <div class="do page">
    <my-header :title="todo.title" :date="todo.date"></my-header>
    <div class="main">
      <div class="nums">
        <div class="bd">
          <label-num v-model="todo.userNum" label="招聘人数(必填)" class="ln" icon="iconstack" desc="个">
          </label-num>
        </div>
      </div>
      <text-area title="总结(必填)"  v-model="todo.summary" icon="iconzongjie" info="招聘级别,姓名,电话" class="plane"></text-area>
    </div>
    <div class="btns" v-if="todo.status!=1&&isMe">
      <small-btn @click.native="confirm(0)" text="保存" bg-color="#598EFE"></small-btn>
      <small-btn @click.native="confirm(4)" text="提交" bg-color="#009C4E"></small-btn>
    </div>
  </div>
</template>

<script>
import labelNum from '../../components/form/label-num'
import textArea from '../../components/form/text-area'
import myHeader from '../../components/header'
import smallBtn from '../../components/base/small-btn'
import { confirmHunt } from '../../api/todo'
import { showAlert, showConfirm, showCorrect } from '../../dialog'
import { parseTime } from '@/util/time'
import { mapState } from 'vuex'

export default {
  data () {
    return {
      todo: {
        userNum: null,
        date: new Date().toLocaleDateString(),
        type: 8,
        title: '人员招聘',
        summary: null
      }
    }
  },
  created () {
    // this.todoId = this.$route.query.id
    // 获取日程信息
    // get(this.todoId).then(res => {
    //   this.todo = res.data
    // })
  },
  computed: {
    isMe () {
      if (!this.todo.id || this.userId == this.todo.userId) {
        return true
      }
      return false
    },
    ...mapState({
      userId: state => state.user.id
    })
  },
  methods: {
    validate () {
      // if (!this.todo.address) {
      //   showAlert('填写地址')
      //   return false
      // }
      if (!this.todo.summary) {
        showAlert('填写总结')
        return false
      }
      if (!this.todo.userNum) {
        showAlert('填写人数')
        return false
      }
      return true
    },
    setAddRessTime () {
      if (!this.todo.address) {
        this.todo.addressTime = parseTime(new Date())
      }
    },
    setSendImgTime () {
      if (!this.sendImg) {
        this.todo.sendTime = parseTime(new Date())
      }
    },
    confirm (type) {
      if (!this.todo.addressTime) {
        showAlert('请点击定位')
      }
      if (type === 1) {
        if (!this.validate()) return
        this.todo.status = type
        showConfirm('是否提交审核', '提交后将不可更改').then(res => {
          if (!res) return
          confirmHunt(this.todo).then(res => {
            showCorrect('操作成功').then(res => {
              this.$router.back()
            })
          })
        })
      } else {
        this.todo.status = type
        confirmHunt(this.todo).then(res => {
          showCorrect('操作成功').then(res => {
            this.$router.back()
          })
        })
      }
    }

  },
  components: {
    labelNum, textArea, myHeader, smallBtn
  }
}
</script>

<style scoped lang="stylus">
  .set-time
    font-size 11px
    color #B9B7C0
    line-height 11px
    margin-left 10px
    display block
    margin-top 10px
    margin-bottom 0
  .do
    overflow scroll
    background-color #F5F4F7
    .btns
      margin 20px 0
      display flex
      justify-content space-between
    .main
      .plane
        margin-top 15px
      .nums
        padding 0 5px
        .bd
          margin-top 20px
          background:rgba(255,255,255,1);
          box-shadow:0px 3px 7px 0px rgba(89,88,87,0.52);
          .ln
            border-bottom 1px solid #ECEAEA
            &:last-child
              border none
    .btn
      margin-top 20px
      height:44px;
      background:rgba(0,156,78,1);
      border-radius:20px;
      display flex
      align-items center
      justify-content center
      dpr-font(15px)
      color:rgba(255,255,255,1);
</style>
